package com.shengde.jinwawaforleader.model.myJob.classList;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shengde.jinwawaforleader.HomeApplication;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.base.BaseActivity;
import com.shengde.jinwawaforleader.bean.User;
import com.shengde.jinwawaforleader.model.myJob.instance_message.Constant;
import com.shengde.jinwawaforleader.model.personalCenter.activity.EditBabyNameActivity;
import com.shengde.jinwawaforleader.model.personalCenter.activity.EditBabySexyActivity;
import com.shengde.jinwawaforleader.network.BaseProtocol;

public class AddClass extends BaseActivity {
	private static final int FINSH_SEXY = 1;
	private static final int FINSH_CLASS_TYPE = 2;
	private TextView tv_back, fill_add, tv_title;
	private RelativeLayout relative_iv_baby_name;
	private RelativeLayout relative_iv_address;
	private RelativeLayout relative_iv_manager;
	private RelativeLayout relative_iv_link_telephone;
	private RelativeLayout relative_iv_class_type;
	private RelativeLayout relative_iv_remark;
	private RelativeLayout relative_iv_name;
	private RelativeLayout relative_iv_baby_sexy;
	private RelativeLayout relative_iv_account;
	private RelativeLayout relative_iv_password;
	private RelativeLayout relative_remark;

	private TextView tv_class_name;
	private TextView tv_address;
	private TextView tv_manager;
	private TextView tv_link_telephone;
	private TextView tv_class_type;
	private TextView tv_remark_one;
	private TextView tv_name;
	private TextView tv_sexy;
	private TextView tv_account;
	private TextView tv_password;
	private TextView tv_remark_two;

	private TextView accountInfo;  ///账号信息
	private TextView classInfo;  //班级信息

	private String mEdtStringRemarkTwo; //备注2
	private String mEdtStringPassword;  //密码
	private String mEdtStringAccount; //账号
	private String mEdtStringNameOne; //姓名
	private String mEdtStringRemarkOne;  //备注1
	private String mEdtStringLinkTelephone; //联系人电话
	private String mEdtStringManager;  //负责人
	private String mEdtStringAddress;  //地址
	private String mEdtStringClassName;//班级名称
	private String mEdtStringSelectSexy;  //性别
	private String mEdtStringSelectClassType; //班级类型
	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
				case FINSH_SEXY:
					if ("男".equals(mEdtStringSelectSexy)) {
						mEdtStringSelectSexy = "1";
					} else if ("女".equals(mEdtStringSelectSexy)) {
						mEdtStringSelectSexy = "0";
					}
					break;
				case FINSH_CLASS_TYPE:
					if (getString(R.string.kingarden_class).equals(mEdtStringSelectClassType)) {
						mEdtStringSelectClassType = "1";
					} else if (getString(R.string.kingarden_branh).equals(mEdtStringSelectClassType)) {
						mEdtStringSelectClassType = "2";
					}
					break;
			}
		}
	};

	@Override
	public void onRoot(Bundle savedInstanceState) {
		setContentView(R.layout.activity_add_class);
	}

	@Override
	public void initView() {
		tv_back = (TextView) findViewById(R.id.tv_back);
		fill_add = (TextView) findViewById(R.id.fill_add);
		tv_title = (TextView) findViewById(R.id.tv_title);
		LinearLayout include_account_info = (LinearLayout) findViewById(R.id.include_account_info);
		accountInfo = (TextView) include_account_info.findViewById(R.id.textview_contact);
		LinearLayout include_class_info = (LinearLayout) findViewById(R.id.include_class_info);
		classInfo = (TextView) include_class_info.findViewById(R.id.textview_contact);

		relative_iv_baby_name = (RelativeLayout) findViewById(R.id.relative_iv_baby_name);
		relative_iv_address = (RelativeLayout) findViewById(R.id.relative_iv_address);
		relative_iv_manager = (RelativeLayout) findViewById(R.id.relative_iv_manager);
		relative_iv_link_telephone = (RelativeLayout) findViewById(R.id.relative_iv_link_telephone);
		relative_iv_class_type = (RelativeLayout) findViewById(R.id.relative_iv_class_type);
		relative_iv_remark = (RelativeLayout) findViewById(R.id.relative_iv_remark);

		relative_iv_name = (RelativeLayout) findViewById(R.id.relative_iv_name);
		relative_iv_baby_sexy = (RelativeLayout) findViewById(R.id.relative_iv_baby_sexy);
		relative_iv_account = (RelativeLayout) findViewById(R.id.relative_iv_account);
		relative_iv_password = (RelativeLayout) findViewById(R.id.relative_iv_password);
		relative_remark = (RelativeLayout) findViewById(R.id.relative_remark);

		tv_class_name = (TextView) findViewById(R.id.tv_class_name);
		tv_address = (TextView) findViewById(R.id.tv_address);
		tv_manager = (TextView) findViewById(R.id.tv_manager);
		tv_link_telephone = (TextView) findViewById(R.id.tv_link_telephone);
		tv_class_type = (TextView) findViewById(R.id.tv_class_type);
		tv_remark_one = (TextView) findViewById(R.id.tv_remark_one);
		tv_name = (TextView) findViewById(R.id.tv_name);
		tv_sexy = (TextView) findViewById(R.id.tv_sexy);
		tv_account = (TextView) findViewById(R.id.tv_account);
		tv_password = (TextView) findViewById(R.id.tv_password);
		tv_remark_two = (TextView) findViewById(R.id.tv_remark_two);
	}

	@Override
	public void initData() {
		tv_title.setText(getString(R.string.add_class));
		fill_add.setText(getString(R.string.sure));
		classInfo.setText(getString(R.string.class_info));
		accountInfo.setText(getString(R.string.account_info));
	}

	@Override
	public void initListener() {
		tv_back.setOnClickListener(this);
		fill_add.setOnClickListener(this);
		relative_iv_baby_name.setOnClickListener(this);
		relative_iv_address.setOnClickListener(this);
		relative_iv_manager.setOnClickListener(this);
		relative_iv_link_telephone.setOnClickListener(this);
		relative_iv_class_type.setOnClickListener(this);
		relative_iv_remark.setOnClickListener(this);

		relative_iv_name.setOnClickListener(this);
		relative_iv_baby_sexy.setOnClickListener(this);
		relative_iv_account.setOnClickListener(this);
		relative_iv_password.setOnClickListener(this);
		relative_remark.setOnClickListener(this);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == Constant.REQUEST_CODE_ADD) {
			if (resultCode == Constant.SETTING_PERSONAL_NAME_ONE) {
				mEdtStringClassName = data.getExtras().getString("person_name");
				tv_class_name.setText(mEdtStringClassName);
			} else if (resultCode == Constant.SETTING_PERSONAL_ADDRESS) {
				mEdtStringAddress = data.getExtras().getString("address");
				tv_address.setText(mEdtStringAddress);

			} else if (resultCode == Constant.SETTING_PERSONAL_MANAGER) {
				mEdtStringManager = data.getExtras().getString("manager");
				tv_manager.setText(mEdtStringManager);
			} else if (resultCode == Constant.SETTING_PERSONAL_LINK_TELEPHONE) {
				mEdtStringLinkTelephone = data.getExtras().getString("link_telephone");
				tv_link_telephone.setText(mEdtStringLinkTelephone);
			} else if (resultCode == Constant.SETTING_PERSONAL_REMARE_ONE) {
				mEdtStringRemarkOne = data.getExtras().getString("remark_one");
				tv_remark_one.setText(mEdtStringRemarkOne);
			} else if (resultCode == Constant.SETTING_PERSONAL_NAME_TWO) {
				mEdtStringNameOne = data.getExtras().getString("name_one");
				tv_name.setText(mEdtStringNameOne);
			} else if (resultCode == Constant.SETTING_PERSONAL_ACCOUNT) {
				mEdtStringAccount = data.getExtras().getString("account");
				tv_account.setText(mEdtStringAccount);
			} else if (resultCode == Constant.SETTING_PERSONAL_PASSWORD) {
				mEdtStringPassword = data.getExtras().getString("password");
				tv_password.setText(mEdtStringPassword);
			} else if (resultCode == Constant.SETTING_PERSONAL_REMARE_TWO) {
				mEdtStringRemarkTwo = data.getExtras().getString("remark_two");
				tv_remark_two.setText(mEdtStringRemarkTwo);
			}
		}
		if (requestCode == Constant.REQUEST_CODE_SECLECT) {
			if (resultCode == Constant.SETTING_SEXY_SAVE_SUCCESS) {
				mEdtStringSelectSexy = data.getExtras().getString("mSexy");
				tv_sexy.setText(mEdtStringSelectSexy);
				mHandler.sendEmptyMessage(FINSH_SEXY);
			} else if (resultCode == Constant.SETTING_CLASS_TYPE_SAVE_SUCCESS) {
				mEdtStringSelectClassType = data.getExtras().getString("mClassType");
				tv_class_type.setText(mEdtStringSelectClassType);
				mHandler.sendEmptyMessage(FINSH_CLASS_TYPE);
			}
		}

	}

	@Override
	public void onWidgetClick(View view) {
		switch (view.getId()) {
			case R.id.tv_back:
				finish();
				break;
			case R.id.fill_add:
				if (TextUtils.isEmpty(tv_class_name.getText().toString())
						|| TextUtils.isEmpty(tv_address.getText().toString())
						|| TextUtils.isEmpty(tv_name.getText().toString())
						|| TextUtils.isEmpty(tv_account.getText().toString())
						|| TextUtils.isEmpty(tv_password.getText().toString())) {
					HomeApplication.showToastShort("带*号选项不能为空!");
					break;
				}
				BaseProtocol.getInstance().addClassInfo(this,User.getSchoolId(this), tv_class_name.getText().toString().trim(), tv_manager.getText().toString().trim(), tv_link_telephone.getText().toString().trim()
						, mEdtStringSelectClassType, tv_address.getText().toString().trim(), tv_remark_one.getText().toString().trim()
						, tv_name.getText().toString().trim(), tv_account.getText().toString().trim(), mEdtStringSelectSexy, tv_password.getText().toString().trim(), tv_remark_two.getText().toString().trim());
				finish();
				break;
			case R.id.relative_iv_baby_name:
				Intent intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "3");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_address:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "4");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_manager:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "5");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_link_telephone:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "6");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_class_type:
				intent = new Intent(this, EditBabySexyActivity.class);
				intent.putExtra("select_radio", "2");
				startActivityForResult(intent, Constant.REQUEST_CODE_SECLECT);
				break;
			case R.id.relative_iv_remark:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "7");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_name:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "8");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_baby_sexy:
				intent = new Intent(this, EditBabySexyActivity.class);
				intent.putExtra("select_radio", "3");
				startActivityForResult(intent, Constant.REQUEST_CODE_SECLECT);
				break;
			case R.id.relative_iv_account:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "9");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_iv_password:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "10");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
			case R.id.relative_remark:
				intent = new Intent(this, EditBabyNameActivity.class);
				intent.putExtra("relative_iv_baby", "11");
				startActivityForResult(intent, Constant.REQUEST_CODE_ADD);
				break;
		}
	}
}
